<?php 
## include required files
/*******************************/
require_once '../model/country.php';
/*******************************/
## Create Objects
/*******************************/
$countryObj = new Model_Country();
/*******************************/

##get country id from edit page as in the hidden form
$editcountryid = base64_decode($_GET['id']);

//echo "<pre/>";print_r($countryArray);
if(isset($_POST['editcountry_btn']) || $_POST['countryname']) {
	## apply PHP validation for required filed
	if(trim($_POST['countryname']) != '' && trim($_POST['ciso_code']) != '') {		
		extract($_POST);
		$countryeditArray['country_name'] = return_post_value($countryname);
		$countryeditArray['name_caps'] = return_post_value(strtoupper($countryname));		
		$countryeditArray['iso1_code'] = return_post_value($ciso_code);
		$countryObj->editCountryById($countryeditArray, $editcountryid);
		
		$_SESSION['msg'] = "<div class='success_msg'><span>Country edited successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=country&page='.$_POST['page']);
		exit;
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please select country and ISO code</span></div>';
	}
	// main if closed
}

if($_GET['id'] != ''&& $_GET['action'] == 'edit') {
	$country_id = base64_decode($_GET['id']);
	$countryDetArray = $countryObj->getCountryDetailsById($country_id);
	$smarty->assign('countryDetArray', $countryDetArray);
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'country');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($countryObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'country/editcountry.tpl');
unset($smarty);
?>